﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCL.Utility;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace CCL.Packet
{
    [Serializable]
    public class PacketJoin : PacketObject
    {
        public char[] Email { get; private set; }
        public char[] Password { get; private set; }
        public char[] Name { get; private set; }

        public PacketJoin(string email, string password, string name)
            :base(CCL.Packet.Packet.Service.Join)
        {
            Email = new char[Packet.EmailLength];
            Password = new char[Packet.PasswordLength];
            Name = new char[Packet.NameLength];

            StringUtility.StringCopy(Email, email, Packet.EmailLength);
            StringUtility.StringCopy(Password, password, Packet.PasswordLength);
            StringUtility.StringCopy(Name, name, Packet.NameLength);

            DataLength = Packet.NameLength + Packet.EmailLength + Packet.PasswordLength;
        }

        public static new PacketJoin Parse(byte[] byteArray)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();

            stream.Write(byteArray, 0, byteArray.Length);
            stream.Position = 0;

            CCL.Packet.PacketJoin obj = formatter.Deserialize(stream) as CCL.Packet.PacketJoin;

            return obj;
        }
    }
}
